﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using YT.Commons;
using YT.DB;
using YT.Modules; 

namespace YT.XH.MeniereDisease
{
    public partial class frmMDInculde : Form
    {
        public frmMDInculde()
        {
            InitializeComponent();
        }

        public bool ShowForm()
        {
            FillCheck(SysVar.SickRecID );
            this.ShowDialog();
            return ValidCheck(); 
        }

        private bool FillCheck(string strSickRecID)
        {
            DBAccess dbcon =new DBAccess (false,false );
            string strSQL="select * from mSickPerson where SickRecID='"+ strSickRecID +"'";
            DataRow drRow = dbcon.GetDataFirstRow(strSQL);
            if (drRow == null)
            {
                initCheck();
            }
            else
            {
                bool blnHasOne = CvtFunc.ToBoolean(drRow["IsInclude"]);
                bool blnBeyondOneYear = CvtFunc.ToBoolean(drRow["BeyondOneYear"]);
                if (blnHasOne)
                    chkOneYes.Checked = true;
                else
                    chkOneNo.Checked = true;

                if (blnBeyondOneYear)
                    chkTwoYes.Checked = true;
                else
                    chkTwoNo.Checked = true;
            }
            dbcon.CloseCon();
            return true;
        }

        private bool initCheck()
        {
            chkOneYes.Checked = false;
            chkOneNo.Checked = false;
            chkTwoYes.Checked = false;
            chkTwoNo.Checked = false;
            return true;
        }
        
        private bool ValidCheck()
        {
            return true;

        }

        private void chkOneYes_CheckedChanged(object sender, EventArgs e)
        {
            if (chkOneYes.Checked)
            {
                grpchkTwo.Visible = true;
            }
            else
                grpchkTwo.Visible = false;
           
        }

        private void frmMDInculde_FormClosing(object sender, FormClosingEventArgs e)
        {
            DBAccess dbcon =new DBAccess (false,false );            
            string strSQL="update mSickPerson set IsInclude= "+ ( chkOneYes.Checked ? 1:0)  +", BeyondOneYear="+  ( chkTwoYes.Checked ? 1: 0)  +" where SickRecID='"+ SysVar.SickRecID +"'";
            dbcon.ExecuteSql (strSQL );
            dbcon.CloseCon ();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
